package com.example.smalldimplestore.base;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

/**
 * Created by 86178 on 2019/11/24.
 * author mogen
 * 用心，成就一切。
 */


public abstract class BaseFragment extends Fragment implements View.OnClickListener {

    private View rootView;

    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        if (rootView == null) {
            rootView = inflater.inflate( setLayoutId(), container, false );
        }
        ViewGroup parent = (ViewGroup) rootView.getParent();
        if (parent != null) {
            parent.removeView( rootView );
        }
        return rootView;
    }

    public abstract int setLayoutId();

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated( savedInstanceState );
    }

    public void showToast(int resId) {
        if (getActivity() != null) {
            Toast.makeText( getActivity(), resId, Toast.LENGTH_LONG ).show();
            ;
        }
    }

    public void showToast(Character text) {
        if (getActivity() != null) {
            Toast.makeText( getActivity(), text, Toast.LENGTH_LONG ).show();
            ;
        }
    }

    /**
     * showToast
     */
    public void showToast(String str) {
        Toast.makeText( getActivity(), str, Toast.LENGTH_LONG ).show();
    }

    @Override
    public void onClick(View v) {

    }

}

